#include<cstdio>
#include<iostream>
using namespace std;
const int N=1e5+10;
int cesu[int(1e6+10)];
int T,n,m,l,vsta,ans,cle,tem;
struct csss{
    int din=0,vin=0,ain=0;
}car[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    for(int j=0;j<T;++j){
        ans=0;

        scanf("%d %d %d %d",&n,&m,&l,&vsta);
        cle=m;
        for(int i=1;i<=l;++i)   cesu[i]=0;
        for(int i=1;i<=n;++i){
            scanf("%d%d%d",&car[i].din,&car[i].vin,&car[i].ain);
        }
        for(int i=1;i<=m;++i){
            scanf("%d",&tem);
            cesu[tem]=1;
        }
        for(int i=1;i<=n;++i){
            if(car[i].vin>vsta){
                for(int x=car[i].din;x<=l;++x){
                    if(cesu[x]>0){
                        ++ans;
                        ++cesu[x];
                        break;
                    }
                }
            }
        }
/*        for(int i=1;i<=n;++i){
//t>40            if(car[i].ain<=0&&car[i].vin<=vsta)    continue;
            if(car[i].ain>=0&&car[i].vin>vsta){
                for(int x=1;x<=l;++x){
                    if(cesu[x]){
                        ++ans;
                        cesu[x]=0;
                    }
                }
            }
            else{
                int v=car[i].ain,df=car[i].din;
                    df+=v/2;
                    v-=car[i].ain;
                    df+=v/2;
            }
            if(car[i].ain>0&&car[i].vin<=vsta){

            }
            for(int x=1;x<=m;++x){

            }
*/
//        for(int i=1;i<=l;++i){
//            if(cesu[i]>1)  --cle;
//        }
        if(ans==0)  printf("%d %d\n",ans,cle);
        else printf("%d %d\n",ans,cle-1);
    }
    return 0;
}
